package com.yupi.project.model;

import cn.hutool.core.bean.BeanUtil;
import com.yupi.yuapicommon.model.entity.InterfaceInfo;
import com.yupi.yuapicommon.model.entity.User;
import lombok.Data;

@Data
public class RequestInfo {

    private String accessKey;
    private String nonce;
    private String timestamp;
    private String sign;

    private UserInfo userInfo;
    private InterfaceInvokeInfo interfaceInvokeInfo;

    public static InterfaceInvokeInfo buildInterfaceInvokeInfo(InterfaceInfo interfaceInfo){
        InterfaceInvokeInfo interfaceInvokeInfo = new InterfaceInvokeInfo();
        BeanUtil.copyProperties(interfaceInfo, interfaceInvokeInfo);
        return interfaceInvokeInfo;
    }

    public static UserInfo buildUserInfo(User user){
        UserInfo userInfo = new UserInfo();
        BeanUtil.copyProperties(user, userInfo);
        return userInfo;
    }

    @Data
    public static class UserInfo{
        /**
         * id
         */
        private Long id;

        /**
         * 签名 accessKey
         */
        private String accessKey;

        /**
         * 签名 secretKey
         */
        private String secretKey;

        /**
         * 羊毛（积分）
         */
        private Long woolLeft;

    }

    @Data
    public static class InterfaceInvokeInfo{
        /**
         * 主键
         */
        private Long id;

        /**
         * 消耗羊毛
         */
        private Long woolUsed;

        /////////限流相关信息
        /**
         * 速率
         */
        private Integer rate;

        /**
         * 时间间隔
         */
        private Integer rateInterval;

        /**
         * 时间单位
         */
        private Integer rateIntervalUnit;

        /**
         * 接口状态 (0- 关闭 1- 开启)
         */
        private Integer status;

    }

}
